package com.hishop.order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hishop.common.utils.PageUtils;
import com.hishop.common.utils.R;
import com.hishop.order.entity.OmsOrderEntity;
import com.hishop.order.service.OmsOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * 订单
 *
 * @author tanwenbin
 * @email 2466082499@qq.com
 * @date 2024-03-13 16:33:31
 */
@RestController
@RequestMapping("order/order")
@Slf4j
public class OmsOrderController {
    @Autowired
    private OmsOrderService omsOrderService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("order:omsorder:list")
    public R list(@RequestParam(value = "key",required = false) String key,
                  @RequestParam("page") Integer pageIndex,
                  @RequestParam("limit") Integer limit){


        log.debug("key------>" + key);
        log.debug("page------>" + pageIndex);
        log.debug("limit----->" + limit);
//        PageUtils page = omsOrderService.queryPage(params);
        //IPage<OmsOrderEntity> iPage = omsOrderService.queryPage(key, new Page<>(pageIndex,limit));


        // Long.parseLong(map.get("ss").toString());  转换值，将从Map中的String值转换成long值
        PageUtils pageUtils1 = omsOrderService.queryPage(key, new Page<>(pageIndex,limit));
        return R.ok().put("page", pageUtils1);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("order:omsorder:info")
    public R info(@PathVariable("id") Long id){
		OmsOrderEntity omsOrder = omsOrderService.getById(id);

        return R.ok().put("omsOrder", omsOrder);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("order:omsorder:save")
    public R save(@RequestBody OmsOrderEntity omsOrder){
		omsOrderService.save(omsOrder);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("order:omsorder:update")
    public R update(@RequestBody OmsOrderEntity omsOrder){
		omsOrderService.updateById(omsOrder);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("order:omsorder:delete")
    public R delete(@RequestBody Long[] ids){
		omsOrderService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
